<template>
  <svg :class="svgClass" :style="styleObj" v-bind="$attrs">
    <use :xlink:href="iconName" rel="external nofollow" />
  </svg>
</template>

<script setup>
import { defineProps, computed} from "vue"

const {color, size, name, margin} = defineProps({
  name: {
    type: String,
    required: true
  },
  color: {
    type: String,
    default: ""
  },
  size: {
    type: Number,
    required: true
  },
  margin: {
    type: Number,
    required: false
  }
})

const iconName = computed(() => `#icon-${name}`)
const svgClass = computed(() => {
  // console.log(name, "props.name")
  if (name) {
     return `svg-icon ${iconName.value}`
  }
  return "svg-icon"
})
const styleObj = {
  fontSize: computed(() => {
    // console.log('size=' + size);
    if (size) return size + "px"
    else return '20px'
  }).value,
  color: color,
  margin: computed(() => {
    // console.log('size=' + margin);
    if (margin) return margin + "px"
    else return '0px'
  }).value
}
</script>

<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: middle;
}
</style>